﻿// <copyright file="TestCommunityCommentsByUrl.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2010-11-16</date>
// <summary>Tester for CommunityCommentsByUrl</summary>

namespace TestWPF
{
    using System;
    using System.Threading;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using NYTimes;

    /// <summary>
    /// Unit test class for <see cref="NYTimes.CommunityCommentsByUrl"/>
    /// </summary>
    [TestClass]
    public class TestCommunityCommentsByUrl
    {
        /// <summary>
        /// Test a URL with comments
        /// </summary>
        [TestMethod]
        public void TestUrlWithComments()
        {
            var waitHandle = new AutoResetEvent(false);

            var comments = new CommunityCommentsByUrl
            {
                ApiKey = "813ad46f5104333600149585f06dd2e3:18:57351476",
                Url = new Uri("http://www.nytimes.com/2010/10/06/opinion/06wed1.html", UriKind.Absolute)
            };

            comments.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                System.Diagnostics.Debug.WriteLine("Property Changed");

                if (e.PropertyName == "IsLoading" && !comments.IsLoading)
                {
                    Assert.IsTrue(comments.Results.Count > 0);

                    waitHandle.Set();
                }
            });

            waitHandle.WaitOne();
        }
    }
}
